Skip to main content

Full text of "The Home Computer Advanced Course 56"

See other formats




é 
Panes i se | ISSN 0265-2919 


90p 


36 








oo rs ta 


4 


IRS.1.15 Aus $2.15 NZ $2.65 SA R2.45 Sing $4.50 





- events. One program calculates the amoun 


THE ARM’S BUILD-UP Having given the 






















ACTS ON FILE The use of databases in 
education not only provides children with 
access to large bodies of information, but 

also allows them to develop useful skills in 
manipulating data 


BUSINESS ON A BUDGET Claimed to be 
IBM-compatible and capable of running 
MS-DOS based software, the Sanyo MBC- 
550 could be considered a real bargain for 
business users. We take a look inside 









NAMING NAMES When setting up a 
database of information, it is essential that 
the designer has clear expectations of what 
sort of data will be entered and how this will 
be used. We look at a basic specification 












ON THE SET We take a look at PASCAL’s 
use of sets, discuss the order of precedence 
of set operators, and develop games of bingo 
and snooker using these data structures 


FROM MONITOR TO MOUSE A weekly 
glossary of computing terms 


















ANCHORS A WEIGH The module we 
develop this week in our simulation game 
consists of those parts of the program that 

report on the weekly progress of the voyage 





LAST CALL We conclude our discussion of 
the BBC Micro’s OS by considering three 
machine code routines that make use of 


of unused memory 








pattern cutouts for the base and arm sections 
of our robot arm in the previous instalment, - 
we now give instructions showing how the 
components are assembled 


COVER PHOTOGRAPHY BY MARCUS WILSON — SMITH ; 

















EDUCATION APPLICATION 


los 
Oh 
















































































aaa 
































>| 


















































e information 


TSE, 


Type YES or NOYES 


You can 


see all the DINOSAURS 
see one DINOSAUR 

ask something else 

go back to Choice Page 





Press A, B, CorD 6 C_ 





1) 
ae os a fa oe 
_ _ cea a : 
sms. 


nit = jeader m nthe 
fe id ‘ol country, the 


cecfaly cord a; ng i dren roa be to 


| children heard hae banxite miners had- gone on 
strike in Surinam | they could quickly discover the 


alae | for 
understand — frei = ee of . sl ihe 
: qu estions es and a5 properly ao organising = th eir “input = 
Those rents ~ who, eter aft er : experiencing - : i 
database, enter higher education and eventually > 
‘the workforce, au surely possess 2 an eee 











have seen how databases can 
manipulate large bodies of related data 
given the fundamentals of proper 
structuring. In our second instalment on 
databases, we will construct a simple system 
based on the idea of an address book, 
highlighting the importance of careful 
planning in the design stage. 


LE a 





fa i iit E sea is i ret 


One of the major advantages of an old-fashioned 
address book is that very little structure is imposed 
beyond basic alphabetic ordering. It is flexible in 
the sense that you can have entries such as: 


PETER GLOVER, 16 Rhiwbinal Cresent, 
Cardiff (0222-601227) 
— his girlfriend’s called Clair — office: 0222 
680545 Ext 160 
— call after 4 — moves to new flat in Jan. 


Followed by: 
GODFREY — 696-1949 
Followed by: 
GREG — see Ashton-Tate 


Using an address book, you are free to list people 
under their first names, their surnames or even by 
‘indirect addressing’ with ‘pointers’ to other 
entries. As soon as a database such as this gets 
transferred to a computer, however, a more 
systematic approach is usually called for. 
- Given that a computerised address book has 
some disadvantages compared with the original, 
let’s design a format for one that will be flexible 
enough to cater for most circumstances. We'll 
consider each field in turn, starting with the name. 

Names come in two parts: the generic half, 
called the surname, and the specific half, called the 
forename. In most countries, the forename(s) are 
followed by the surname, whereas in China, 
Japan, Hungary and some other countries, the 
surname precedes the forename. In Japan, there is 
only ever a single forename (except that it follows 
the surname), while in a Chinese community in 
England, it is customary to have an English 
forename as well as a Chinese forename. Thus, Li 
(surname) Yu Chow (forenames) will be known to 
most of his English friends as Paul. 

Already, we have plenty of opportunity for 
confusion, and we're only considering the name 
field. Clearly, we will have to impose some 
discipline, and decide whether forenames or 
surnames are to come first, and how long an 
‘allowable’ name may be. Names may be as short 
as Ng or aslongas Cholmondley-Smythe, possibly 


1104 THE HOME COMPUTER ADVANCED COURSE 


NAMING NAMES 


even shorter or longer, so we must always allow for 
extreme examples. If the database manager 
(DBM) uses fixed length fields, we will have to 
choose a field length more than adequate for the 
longest name we are likely to encounter. (The 
disadvantages of fixed length fields will be 
discussed later in the series.) 

If we have to impose a format, as indeed we do 
when designing a database, it is probably simplest 
to use the surname field as the primary key field, so 
we will start with the surname and follow it with 
one or more forenames. The address also poses 


problems. Doubtless, you have seen clip-out 


forms in American magazines that ask for your 
City, State and Zip Code. British addresses simply 
don’t fit into that format. A further complication 
arises when you consider that even the ‘Name, 
House Number, Street, City, County, Country’ 
format is not always appropriate. In Japan, for 
example, the city is listed first in an address, 
followed by the district within the city, followed by 
the lot number of the building plot within the 
district, with the addressee’s name coming last. » 


A BASIC SPECIFICATION 


In this simple database example, as in more 
complex ones, it is probably not possible to cater 
for every conceivable combination, so we will 
have to settle for a compromise. Assuming you are 
never likely to be communicating with someone 
having 16 forenames, let’s see how well the 
following basic skeleton would work: 


@Surname Field — up to 40 characters 
@Forename Field — up to 60 characters 

@ Address Field 1st Line — up to 80 characters 
@ Address Field 2nd Line — up to 80 characters 
@ Address Field 3rd Line — up to 80 characters 
@ Address Field 4th Line — up to 80 characters 
@ Address Field 5th Line — up to 80 characters 
@ Telephone Field — up to 20 characters 

®@ Note Field — up to 80 characters 


This basic specification should cover most 
eventualities, though there may still be problems. 
One potential difficulty is the limited length of the 
Note field. Another problem is that Country is not 
specified as a separate field. Depending on the 
length of the address, the country could be found 
in the third, fourth or fifth address fields, or not at 
all. This would not normally be a problem until we 
wanted to search our database using Country as a 
key. If your database application had to deal with 
many foreign correspondents, it might be better to 
design the database with a separate Country field. 
Decisions such as these will always be needed at 
the design stage. 








The DBM you run on your computer will 
determine the ease with which you can implement 
a specific database on your system. One of the 
very simplest DBMs is Caxton’s Card Box. The 
program has limited facilities for extracting and 
manipulating data, but if your requirements are 
straightforward, it will give you the results you 
need with the minimum of fuss. Card Box does not 
give you a sophisticated programming language to 
manipulate fields or records. It does, however, 
allow you to extract specific records by entering 
simple commands at the keyboard. Using Card 
Box to create the database outlined above, you 
need only to load the program and follow a simple 
sequence of entries. 


USING CARD BOX 


The first thing you have to dois decide on a format 
for the record. This format determines what 
information will be stored, how it will be indexed 
(that is, which fields will be designated as ‘key’ 
fields) and how the records will actually appear on 
the computer screen or printouts. If we call the 
database file ADBOOK, Card Box will create a 
format file called ADBOOK.FMT. This can be edited 
if required to alter the way the information is 
displayed. Alternative format files can also be 
created to display the database information in 
different ways. 

As with most DBMs Card Box allows you to 
enter ‘permanent’ text in each of the fields. In the 
case of an address book, it is pretty obvious what 
the significance of each field is: John Smith is 
clearly a name and not part of an address¢ 
similarly, 0222-680545 is obviously a telephofe 
number. In other databases, you might need to be 
reminded what the significance of each figid 1s. 
This is where ‘permanent’ text comes inflandgy. 
Compare these two records: 


06116 
3995 
86 
34.75 
Dongle with widget nozzle 

and 
MAKER’S PART NUMBER volo 
OUR PART NUMBER cole 
NUMBER LEFT IN STOG ce 
PRICE Oe 
DESCRIPTION Dong vce oe 


The informationds identical in both cases, but the 
second examplé, with permanent text that appears 
in every record, makes mistakes much less likely. 

Card Box allows each field to be given one of 
four possible indexing attributes: NONE, MAN(ual), 
AUTO or ALL. In a stock database, it is unlikely that 
we would ever need to use PRICE as a Key field; you 
are not likely to ask: “Do you have any parts that 
costless than £40 and more than £307?’ It is quite 
possible, however, that we would need to know 
how many #06116 items are still in stock, so that 


MAKER’S PART NUMBER would need to be made 4 
key field. 

Returning to our address book example, ware 
sure to want to search the database by Namg, and 
probably by Forename too. Both of these’ would 
need to be made key fields. If we were maining a 
business, we might also need to search 4ecords Dy 
City and possibly even by telephone area dialling 
code. It is important to remember that you Cannot 
create an efficient database until you have worked 
out how you are going to use it. Unlike the old card 
indexes, databases require that you anticipate 
beforehand how you are likely t6 use them. 


Design Elements 

Megafinder allows you to degign your Own Toms. 
This one was derived from@ne Same 1orm, Supplied 
ready-made with the program, used in Our Oiner 
screen display 


Business Card File 


Company? 

Address: 

Gets: D 
Phone: 

Keywords: 


Comments: L 


Layout: {mark fields with ".", CTRL-B ins. ae, CTRL-N del. 


line, CTRL-C¥3 





COMMAND LINE 

1)1S Shows Some O1 ine 
commands thal may be used 
When ediing 2 desig) Lines 


and Chalaciers ay De inceriec 
and deleted, and tne (nisied 
design Can be Saved 10 disk Dy 
pressing UIRL-U 


Company: Home Computer Advanced Course 
Address: 14 Rathbone Place 
Town : LONDON Code:W1P 1DE 
Telephone:@1 631 14393 


Contact:STEPHEN COOKE \STEVE MALONE 


Keywords: PUB * WEEKLY * 1.68 


Product received:Subscription 


Actions: 25/5/85 renew sub 


Find: lindex 1 = ACD 
Deelete Ptrint Qtuit 


Meatch = OFF ¢arrows> Jtump Cthange 





FIELD LENGTH 

These are indicated by underjine 
CharecierS(_) |e tdi lengin 
Ol all he fields in a ionn 
determines 10W many (01s 
May be Siored in a iile. 
Thereiore, | makes sense io 
Keep eds 4S 501 ass 
practical, Dealing in mind ihe 
nature of (he dala inal will be 
eniered 


FIELD LABELS 
These are entered Dy ine user 
when designing ie (orn and 0 
1S Dr0dT al), ale enlirely (01 ine 
user s convenience. (fe 
program uses iiem) wien 
displaying lormation on ive 
Screen Dut takes 10 account Oo! 
field iabels when sorting dala, 
whicn iL coes using FIELD 
IDENTIFIERS 


FIELD IDENTIFIERS 

Nol io be coniused wilh ie 
FieLD LABELS, ne identiiers 
celery ine fe order in which 
fields will be accessed wien 
entering iniormation. Identifiers 
also enable fields to be Soried 
Separalely oF in groups. Using 
Megalinder 5 INDEX Option, 
allocating (eld U io Index | 
would allow te user 10 Sort 
Quickly through ine different 
records according to ine 
alphabetical arrangement ol 
cies 


Allow Us To Show You Our Card 

Database management Systems nay 
offer several different methods of 
manipulating information. This screen 
dump of Megafinder, a DBM running on 
the Apple computer, shows a selected 
record from atilenamed Business Cara 
and, below this, alist of command 
options. Data held by the program can De 


sorted into up to tour different INDEXes 
to speed information recovery. [he DBI 
will also search for a AICH between 
input data and stored data, JUMP to 
Specified sections of the database (€.9. 
to the section holding company names 
Starting with IM), CHANGE and DELETE 
information, and PRINI a record or 
report, either to the screen or a printer 


THE HOME COMPUIER ADVANCED COURSE L105 


veonononseganenenecanannanssnnse 





_At the start of the journey, each crew member's 
strength is set at 100 in the array TS(,). The 


a makes a weekly. calculation to check it far and the money remaining. The accumulated zg 


at line 800, and is increased by the weekly wage | 


| 


ANCHORS 











Having everything we need to se 
New World in our tradi } 
we can lift anchor, 


gggeetten, 








there are sufficient stocks of each provision to last 
the journey. If supplies ofa particular type run low, 
the player is asked if the crew should go onto half 


be issued for one week and would reduce the crew. 


. pena by five units. 


If one type of supply becomes: mie: each 
ctew member’s strengthi 1s reduced by 10 for every 
~ week they are without it. For example, should the 
Serew run out. of fruit and: be on\half rations of 
water, their weekly strength rating would decrease. 
ae 15; if the water ran out ——- ine pein 


a 


issued at the Sau of the next eck ae ee et 
The health of the crew is given. at th Ae = pesmi ~ 


of each week by the subroutine at line 4000.-There ~ 












are five classes of health, which are determined. by 
strength rating. The highest classification is very. 


healthy (strength rating 75 — 100), followed by 
healthy (50 — 75), sick (25 — 50) and very sick (1 - 
25). When the strength rating reaches 0, the crew 
member dies and is buried at sea, but the wages of 
the deceased are still accounted for each week and 
paid to the next of kin when the ship returns to 
port. This subroutine also gives the wage bill for 


1106 THE HOME COMPUTER ADVANCED COURSE 


eter can be | 
tes hae 


: “weeks, 


AWEIGH 


the coming , week, the total wages for the voyage Som 


wage total is reset to zero at the start of this section, 


bill each time through the loop. If the bill becomes | 
~~rations of that provision: ‘The half rations will only: ~Jarger than the balance of gold (as checked bythe. 


subroutine at line 5000), the player is warned that _ 


\a trading profit will be needed to pay the crew. 


If all goes well, the voyage should take eight 
but ‘unforeseen circumstances “could 
increase. the value. Line 801 creates a string 
variable, ‘HS, to\ indicate if the crew are on half 


%, 


rations. The routine determines the- strength and—. 


_type of each crew member by checking the type/ 
—_ — TS(, ) L sets ab a ot at line 4060 


t 


| 


i 


program Sat to line At i0. if there’ iS eon se 


the « crew. aie in a anray, fe 4075; prints the 


must be ecole in the yan s log 

strength rating indicates death, each empty section 
on the array would appear to represent a dead 
crew member. To avoid this problem, it is reset to 
-999 for one week when a rating reaches 0. At the 


i 
i 
j 
so 


4 
Hy 























a ee Sn a a a ee ee pn aae 





PA(), is greater than zero. If this is not the case then 
the strength of each crew member is reduced by a 
factor of 10. This reduction is actually handled by 
a small subroutine at line 9300 that reduces the 
strength rating of each crew member by the value 


























of WF. This subroutine can therefore be used to 
reduce the crew strength by differing amounts. We 
: <so...need only to set WF to the desired value before 
ae ~ calling: -the subroutine. 
Si SS ge == =* Ee the amount of ea remaining 1S greater 


a 





Nateat orovision | 
~yoyag e. ate ao is calculated: mM. line 5180 


age 


the voyag : tt oc, 


Nis given the’ ‘option.of placing ‘the crew on half 
_Tations. ‘of that.particular.type-of provision. 


status of each provision type (whether on half or 




























= iS ie ae the projected requirements, the: player. : 





} aa 
i oe 
Da 


A full \ ano) is indicated by \the array HR() a = 
\ DIMensioned at line'802. When on full rations the. \ a 
—- “ts ‘array 6 eitientiis set tot ifth e particular provision ° a <= : 
“Cis reduced to half then the c responding airay \ : 
, “oo élement jis set to 0.5. If the crew is on half rations . . s 
aS See =e thesubroutine at line 9300 \— 
| \\ _ the strength rating of each crew membet by five, \ 
| : Ss The final check made\by this\ routine before, \ ‘ 
| = uing the ration i s to see if the amount of the | He: — 
oS Se a eee vision remainin; is less than the amount to be \ 
ar ed. If this is the case, then only the amount | 
aining is issued and, to indicate that no — | | 
visions. are left, the corresponding element Of .)....00c0.0c cfm et 
| h provision array is set to -999. | 
end of the week it is set back to 0 and the roar | | / 
| informs of the death at the start of the next wee Ss 
a= ~ Re-setting it — it to ae that ‘rating == — = 
4 panne the following weeks. This anetet a j / | 
i record of dead crew members at the start of each / / / 
Clo oo of rageate eth pee is. =e =. = 
checked by lines 4080 to 4098. Their rati 2 - 
| ‘matched against the four states of health, an fine / 7 a 
4099 vil print the state of each. The strength/ = Ss 
hc ~~ type loop ends at 4110, which sends the program . ys Ss 
' back to look at the next section of/the aryay. / J x 
| The weekly wage bill iS calculated usin another ae we 
= : --loop between lines 4120-and-4135, and uused-once- oS eS 
| _ for each of the five crew types. Wages for each type —_—— = 
| are calculated by the/ equation at line / / oe — 
Tamil multiplying the count, for each type by the wa | 


ew, | See we a ree eek Aer ely A 


rate, and accumulating it/in the variable, iW. 

Created and set to 0 at the start of each week by 
' tine 4119, WW represents ‘the weekly wage, printed. 
Sale tine 4145. Ttis — to the <— for. the 






a ; for ‘each mon a several 
| checks a are made on the level of rations remaining. 
The first of these is a check to ensure that some 
rations remain. This can be tested by simply 
checking that the amount of the provision, held in 





THE HOME COMPUTER ADVANCED COURSE 1107 








ERRATUM 
In the listing of our adventure 
game Digitaya, on page 1020, 


BBC Micro users should 


change all occurrences of the 
variable names LNS() to LS() 
and LN toL 





PROGRAMMING PROJECTS /SIMULATION GAME 





Module Four: The Voyage 25 scent 
0 ul e ou a y g 42325 PRINTOAC1)::S¢="BOTTLES OF MEDICINE*":GOSUBS1 


a 


Length Of Voyage Variable 423 GOSUBS2a0 


: 4332 IFOAC2) =@THENS342 
40 oe reN Dee ee 4325 PRINTOAC2): :SS="GUNS*" :GOSUB9S100 
43460 GOSUBS268 


4 4342 IFOA‘3)=Q@THENS352 
Main Voyage Loop 4345 PRINTOA(3)::S$="BAGS DOF SALT*":GOSUBS100 
800 WT=0 4350 GCSUBS2eaa 
@@Q1 HS="N" +REM HALF RATIGN INOICATOR 4352 IFOA(4)=0THENS362 
@O2 DIMHR(4):!HR(1)=1SHR(2)=13HR(Z)=11HR64)=1 94355 PRINTOAC4)::S#="BALES OF CLOTH*":GOSUBS100 
820 FORWK=1TOJL + REM MAIN VOYAGE LOOP 43660 GOSUBS200 
S25 GOSUB49@@a: REM CREW STATUS REPORT $362 IFOACS)=@THENS3S 72 
830 GOSUB4200:REM PROVISIONS REPORT 4365 PRINTON(5): 'S#="KNIVES*":GOSUBS100 
835 GOSUB4300:REM OTHER GOODS REPORT 4370 GOSUBS200 a 
840 GOSUBS2O0:F 2 INTCHRS¢ 147 > 4372 IFOAC6)=OTHENS388 
Sde PRINT: PRINT*PRINT 4375 PRINTOAC6)? ':S#="JEWELS*" :GOSUBS100 
843 S$="I1T IS ESTIMATED THAT THE VOYAGE *":GOSUBSIO 94380 GOSUBS200:PRINT 
a 4382 PRINT"YOQU HAVE"; #:S$=" GOLD PIECES LEFT*":G 
844 PRINT"WILL TAKE A FURTHER": JL-WK +1: "WEEKS" OSUBS 108 L 
845 GOSUBS208 4384 GOSUBS20a 
@46 PRINT: S#=K#!GOSUB9S100 4397 PRINT: S#=K#$:GOSUB9100 
e447 GETIS: IF 1#=""THENS47 9398 GETI#: IF I$=""THEN4398 
850 GOSUB5S@@@:REM CHECK WAGE BILL 4399 RETURN 


S55 GOSUB5190: REM ISSUE RATIONS 
889 NEXT WK 


Wage Bill Subroutine 
Crew Status Report 5@@@ REM CHECK WAGE BILL 

50@5 IFWT>MOTHENSO10 
4ag@ REM CREW STATUS REPORT 5aa@g GoatTosa99 
4010 PRINTCHRS( 1473) S@1i¢i PRINTCHR$(147) 
4@20 St=" CAPTAINS LOG*":GOQSUB910@0 5020 PRINT:PRINT!IPRINT 
4025 st-" =: ";GOSUBS 106 5@25 St="THE CREW HAVE HEARD A RUMOUR*":GOSUBS100 
4030 GOSUBSeaa 5038 S#="THAT YOU DON'T HAVE ENOQUGH*" :GOSUB9160 
4035 PRINT"AT THE START OF WEEK": Wik 5035 S#="GOLD TO PAY THEM AT THE ENDx*":GOSUBS100 
4040 SH="THE STATE OF THE CREW I[S:x" '+GOSUBS 100 5040 S$="OF THE VOYAGE. *":GOSUB9100 
4045 GOSUBS2AMa:PRINT : 5045 GOSUBS2ZQ0:PRINT 
4055 PRINT SAQS5SQ S$="THEY ARE GETTING ANGRY !!%*":GOSUB9S100 
4@60 FORT=1TO16 5055 GOSURS200:PRINT 
4070 IFTS(T,1)=O8THENS110 5Q@6Q@ S#t="LET'S HOPE YOU MANAGE TO MAKE*":GOSUB9S10@ 
4@75 PRINTC#(TS(T,-1)39:" cP: 
4078 IFTS(T,2)=-S999STHENSS="DEAD !1!!11!11)2*":GOTO489 GAGS St="A TRADING PROFIT! *"!:GOSUB91O09 
g 5066 GOSUBS20a8 
4Q@2Q IFTS(T,2) >75THENS#="VERY HEALTHY) *":GOTQ4099 SATA PRINT: S$$=K$:GOSUBS100 
4085 IFTS(T,2) >SOTHENSS="HEALTHY?*":GOTOS8033 5@e0 GETI$: IF1$=""THENSOSa 
4a95 IFTS(T,2)>2S5THENSH="SICK | >*x":GOTQ4a9qa 5999 RETLRN 
4098 St="VERY SICK |! >" 
4a99 GOSUBS100:GOSURS2a0a0 : : 
411@ NEXT T issue Rations Subroutine 


att) Goebevede re 5106 REM ISSUE RATIONS 


5103 PRINTCHRS#( 147) 


8 5105 S#=" ISSUING RATIONS*":GOSUB9100 
Weekly Wage Bill 51Q6 S#s=" as ee Se x": GOSUBS9100 
4118 WhW-6 5107 GOSUBS2Q@:PRINT"WEEK "? WK: PRINT 
4120 FORT=1TQ5 : 5108 Hp="N" : 
4130 khl=WW+ (CO CT *eWG(T)? S110 FORT-1TO4 
4135 NEXT 5112 HR¢T)=1 
4140 S#$="WWAGE BILL FOR THE WEEK*"” 'GOSUBS100 5115 IFPACT) >@THENS180 
4145 PRINTWW: "GOLD PIECES" 5126 PRINT"NO ":P#C(T):" LEFT! !)!":GOSUB9200 
415@ GOSuBSs2eaa 513@ S#="THE CREW IS GETTING WEAKER !!*":GOSUBS91@0 
4155 WT=WT+h 
416@ S#="TOTAL WAGES FOR VOYAGE SO FAR: *":GOSUBS1@ 5125 WE=109:GOSUB93a0 
a 5139 GoTaseasa 
4165 PRINTHWT: "GOLD PIECES" 5180 *=(PNCT) eCNd*¢(JIL—-WK+I> 
4170 GOSUBS2H90 5185 IFPACT)<XTHENS2o0a 
4175 PRINT"MOGNEY LEFT = ":MO: "GOLD PIECES" 5190 GOTOSe272a 
418@ PRINT:S$=K#! GOSUBS 100 5200 PRINT"RUNNING SHORT OF ":P$¢T) 
d18a@Q GETI#: IF IS=""THENG19G 5205 GoOSuURS2zaa 
4199 RETURN 5210 S#="00 YOU WANT TO PUT THE CREW ONx":GOSUB910 
a ; 
_. 5215 PRINT"HALF RATIONS OF ":P#(T) , 
Provisions Report 5220 INPUTI$: I$=LEFTS(I#, 1) 
a2an REM PROVISIONS REPORT 5221 IF 1#<¢>"Y"ANDO I1$<>"N" THEN 5220:REM INPUT ERR 
4205 PRINTCHRS( 147) OR . 
4206 PRINT"AT THE START OF WEEK": bK:GOSUBS2aa see> iF ie Yee ee 5 
4210 S#="YOU HAVE THE FOLLOWING«*":GOSUB9190 Se3@ HR¢T)=.5tHe="¥ 
4215 S#="PROVISIONS LEFT: *":GOSUBS1aa sere eee 
gee be nt eocueseon 5250 S$="THE CREW IS GETTING WEAKER! «":GOSUB9100 


SerO X=PNCTI *HRCT)*CN 
Sere IFX>PACT) THENK=PACT >? 


4225 FORT=1T04 
4226 IFPACT)=Q@QRPACT>=-S99THENS240 


4230 PRINTPACT):US(T):"S OF ":P#(T) pers FAC TORPACTO 

4232 K=INTCPACT)/CCNEPNCT))) 5e80@ IFPA‘CT)=@THENPA‘CT)=-399 

4235 PRINT" (ENOUGH FOR":%:" WEEKS)" 5285 PRINTX:US(T):"S OF ":P$(T):" ISSUED" 
4239 GOSUBS2aa 5290 PRINT: GOSUB920@: NEXT 

424@ NEXT 5295 PRINT: S$=K#:GOSUB910@ 

-42930 PRINT:S#=K#:GOSUB91@0 S298 GETI#: IF 1$=""THENS298 


4295 GETI#$:! IF 1S=""THEN4295 S233 RETURN 


4299 RETURN 


Reducing Crew Strength 
Other Goods Report 9300 REM REDUCE CREW STRENGTHS BY WF 
42@@ REM OTHER GOODS REPORT | 9310 FORS1=1T016 
43@5 PRINTCHRS( 147) 9320 TS(S1,2)=TS(S1,2)-WF 
436 PRINT"AT THE START OF WEEK "+ Wk !GOSUB9200 9330 IFTS(S1,2)<1THENTS(S1,2)=-999 
4310 $$="YOU ALSO HAVE: x":GOSUB9 10a 92408 NEXT 
4320 PRINT: GOSUB920a 9399 RETURN 






1108 THE HOME COMPUTER ADVANCED COURSE 





BUSINESS ON A 


BUDGET 





IBM PC 
under £1,000, the Sanyo MBC-550 
represents a less expensive addition to the 
16-bit Intel 8088-based computer market. 
But hardware restrictions and a lack of 
specifically designed software, at least for 
the present, limit this otherwise sensibly 
produced machine. 








Despite rapidly falling prices of 16-bit processors, 
most computers based around 16-bit technology, 
apart from the Sinclair QL, are still very expensive. 
It is hard to understand why this is. Sinclair 
Research had proved that it is possible to produce 
a 16-bit machine profitably for under £400, yet 
most comparable micros are well into the four- 
figure range. The reason probably lies with the 
type of customer who is in the market for such a 
machine. These tend to be business users whom 
manufacturers seem to believe can afford to pay a 
bit extra. This appears to be particularly true of 
computers based around the Intel 8088 series of 
processors and is probably linked to the sales 
policy of the market leader, IBM. 

With the standard IBM PC including a single 
disk drive costing around £2,000, most 
manufacturers building 8088-based micros 
consider that by shaving a few hundred pounds off 
this price, their customers will regard that as a 
bargain. But this still leaves a section of the market 
that cannot quite afford many of these, although 
still requiring a computer for business use. Until 
recently, this area of the market was occupied by 
business computers based around the Z80 
processor that were equipped with disk drives 
enabling them to run CP/M. However, many 
manufacturers are now realising the potential of 
this neglected area of the business market, and are 
endeavouring to produce inexpensive 8088-based 
machines. 

The Sanyo MBC-550 is one of the first of these 
to arrive on the market. Although Sanyo does not 
claim it to be compatible with the IBM PC, the 
MBC-550 does run the de facto standard MS- 
DOS disk filing system. ‘The machine is available 
in either a single or twin disk version and sells for 
around £1,000. 

Like most business machines, the MBC-550 
has two separate units, comprising the keyboard 
and the main computer. These are sturdily cased in 
a combination of metal and plastic, finished in a 
metallic silver. The keyboard is divided into three 
sections. On the far left are five programmable 
function keys which, when used in conjunction 
with the Shift key, produce a maximum of 10 


functions that vary according to which application 
is currently in use. In Basic, these keys can be used 
as single keyword entries with commonly used 
commands such as LIST, LOAD and RUN. 

The typewriter keyboard is well laid out with all 
the control keys in their usual positions. The 
control keys include a destructive Backspace and 
an Insert/Delete key, only one of which is 
operational in each application. There is also a 
very large Return Key, four times the size of one of 
the normal keys. On the nght-hand side of the 
Space bar is a Graphics key, which produces 
graphics characters on the screen when locked. On 
the far right-hand side of the keyboard is a 
numeric keypad that can be used as a calculator, 
or, if the Number Lock key is pressed, as a cursor 
control to enable full screen editing in BASIC. 





The computer itself is a large flat box about the 
size of a video recorder, that has been made large 
enough to accommodate the optional Sanyo 


monitor. Like the keyboard, it is mostly 
manufactured of sheet metal. On the front of the 
computer is the power switch and space for two 
disk drives, although our illustration shows the 
single drive model. The drives used by the MBC- 
550 are of the standard 5zin floppy disk variety. 
On the front of each drive is a clip to hold the disk 
in position and prevent it from being removed 
while the drive head is reading it. 


Sibling Differences 


The Sanyo MBC-550 is a budget 


priced 16-bit business machine 
which runs under the popular 
MS-DOS operating system. 


. There are two versions of the 


machine: the MBC-550 is the 
single drive version and the dual 
drive configuration is known as 
the MBC-555. The monitor 
shown here is not included in 

the basic price of around £1,000 


CHRIS STEVENS 


THE HOME COMPUTER ADVANCED COURSE 1109 





Bi 
a 


CE 


PERIPHERAL INTERFACES 


The rear of the computer contains the power 
supply and the peripheral interfaces. Looking at 
the back of the computer, on the left side, you will 
see the power cable, the fuse housing and the earth 
connection. On the right, there is a Centronics 
parallel interface that will accommodate the 
connecting of a printer. A pair of monitor sockets [| = = 
are to the right of this. The first isan RGB socket, [| 
enabling the computer to run a colour monitor, [= 
while the other is a composite video jack that plugs 
| into the Sanyo green monochrome monitor. 
Above these interfaces are further expansion ports 
provided to accommodate extra peripheral 
interfaces at a later date. 

The Line port above the printer interface is 
included for the connection of an RS232C serial 
interface that would facilitate the computer 
communicating with other computers, via a 
modem, or with any other serial device, such as a 
printer. Next to that is a port in which an MBC 

7 series or Apple-compatible joystick interface [= = = = = 
could be fitted. This not only allowsajoysticktobe | Srinterinterlace 
fitted but would also enable the computer to be | Thisponaliowsany — 
controlled from a trackball, paddle or other | GeMlonics compatible paralie) 
external device. There is also an external bus —'[ se 
socket allowing other peripheral devices to be | 3 
interfaced. 

Unlike many manufacturers who object 
strongly to users tampering with their machines, 
Sanyo has thoughtfully included, in the user 
manual, instructions for the fitting of all of these 
peripheral interfaces, extra banks of RAM and a 
second disk drive if only one is currently fitted. | 0 
This is a very welcome inclusion, although the | Perinieral itertace Gi — 
guide does mention that users should consult a | co ee LD 
qualified engineer if they are at all uncertain. The |~ ee tothe computer 
rest of the user manual is equally helpful. It | = = = = = 
contains a glossary of computer terms, a full 















NideoChip-~ 
_ Thischipallows any section _ 
_ of the 256 Kbyte RAM area to 
_beusedforvideoRAM 
_ storage y 


oe e 
Be 


es 


iy 
= 
. 


Bis. 
ee 


pais 


_ The computer's sound — 


capability is channelled 
1110 THE HOME COMPUTER ADVANCED COURSE _ through this built-in speaker 











tutorial description of Sanyo BAsic — including 
instructions on using the disk system from BASIC — 
and a wealth of technical information. 

Sanyo BASIC, a derivative of Microsoft’s version, 
is certainly adequate, although it seems to be 
somewhat slow in_ processing arithmetical 
functions. The 8088 chip has long been noted as 
being sluggish when processing maths (hence the 
popularity of the 8087 maths co-processor), but 
the MBC still seems noticeably slower than most 
other 8088-based machines. Similarly, line 
drawing on the MBC-550 is also very slow. This is 
because Sanyo BAsic lacks a DRAW command, 
requiring line drawing to be performed by the 
PSET command, which simply turns on one 
specified pixel to a particular colour. Thus, 
drawing a line involves using a loop. 

Apart from standard Microsoft-type 
commands such as MIDS, LLIST and CIRCLE, there 
are also commands to define and view windows on 
the screen. Structured programming is 
encouraged by the inclusion of the WHILE. .WEND 
conditional statement. Many Sanyo BASIC 
keywords can be entered by two or three 
keystrokes based around the Control key. For 
example, the keyword DIM can be entered by 
pressing CTRL, SHIFT and D simultaneously, while 
PRINT is entered by pressing CTRL and P. Although 
any move towards the simpler entry of BASIC 
keywords is to be welcomed, and many of the 
shortened keypress commands bear a relationship 
to the originals, it is difficult to imagine anyone 
attempting to remember the 40 commands 
available to write BAsic programs. More likely, 
they would attempt to memorise a few of the more 
commonly used shorthand versions. 

Bundled with the Sanyo MBC-550 is an MS- 
DOS system disk, which also contains the Sanyo 
BASIC, the widely used WordStar word processing 
package and the CalcStar spreadsheet. 
Accompanying these packages is a manual giving 
full descriptions on how to use them. , 

One would expect the standard MBC-550 — 
based around the 8088 chip and running under 
MS-DOS — to have little problem running the 
vast amount of IBM PC software that is available. 
But the fact is that hardware restrictions within the 
machine meant that none of the IBM-compatible 
packages that we tested on the computer would 
run. 

There is undoubtedly a market for low-priced 
MS-DOS business machines able to run IBM- 
compatible software. The question is not whether 
they will appear, but when. The Sanyo MBC-550 
is a first attempt to break the £1,000 barrier, but 
unfortunately its lack of compatibility means that 
it will remain isolated. For the small business 
owner who only needs a computer to run 
competent word processing and spreadsheet 
facilities, the MBC-550 seems to be good value. 
However, anyone wishing to gain access to a wider 
software base than is available for the Sanyo will 
have to reconcile themselves to either spending 
quite a bit more, or else waiting a little longer. 





THE HOME COMPUTER ADVANCED COURSE 1111 





LOWER BASE 


EXPANDED VIEW 


UPPER BASE 


FLANGED BALL-RACE 


STEEL DOWEL 


SIDE ELEVATION 


6mm BRASS TUBING 











6mm BRASS TUBING 


THE ARMS 
BUILD-UP 


6mm CROSS PIECE 





_ 6mm CROSS PIECE 





| SIDE PIECE 
LOWER BASE 


SPACER 


1112 THE HOME COMPUTER ADVANCED COURSE 








After listing the necessary parts for our 
Workshop robot in_ the previous 
instalments, we can now _ begin its 
construction. Here we assemble the main 
body, the upper and lower arm sections, as 
well as make the elbow and shoulder joints 
using the previously cut out parts. 


a fas 3 
ee 
Benne 
a 
a 2 se 

_ 





44° 


. —— — sprees 
. oe a 
9 ae & SS 
4 } d als p ae 
k : q 


a 





SS 








Th 











‘4mm EXTERNAL 


5mm EXTERNAL ar 
DIAMETER TUBING. 


DIAMETER TUBING 













_. 6mm CROSS 
PIECES — 









— SERVO MOTOR 
— SERVO ARM 





4 








-GLUEING WRIST SPACER - 









6mm WRIST SPACER, 











| ANDNUT 


5mm EXTERNAL 
DIAMETER TUBING = 





_OWER ARM PIECE 


THE HOME COMPUTER ADVANCED COURSE 1113 


MAINBODY 
SIDEPIECE 


Step 3: Upper A 
| Assembly 


'T’ PIECE 





(Q) MACHINE SCREW 








| UPPER ARM PIECE 


‘4mm EXTERNAL 
DIAMETER TUBING 















m| 


KEVIN JONES 








In addition to pascav’s familiar data 
structures, such as arrays and files, the 
language also includes sets and records. We 
examine the first of these structured types, 
as well as summarising the levels of 
precedence for the PASCAL operators we have 
examined so far. 





We often talk about a computer’s character set. 
But what precisely is meant by a set and how does 
it differ from an array? The main characteristic ofa 
set is that it is a collection of objects that can be 
processed as a single entity, rather than each 
element having to be accessed individually. A 
practical example would be the set of all people 
who program in PASCAL, or the letters of the 
alphabet that are vowels. There is often no 
particular ordering involved, with the only 

question of interest being: is this particular object a 
_ member of the set or not? 

_ For reasons of efficient implementation, PASCAL 
places some restrictions on sets. They can only 
have simple scalar types as their members — not 
arrays or other structured data — and there will be 
an (implementation-defined) upper limit on the 
range allowed for this “base’ type. The syntax is 
straightforward, for example: 


TYPE 
Numbers =SET OFO. .127; 
Alphabet =SETOF‘A’.. ‘2’; 
ColourMix = SET OF ( Red, Green, Blue ): 


The range of possible values of the ordinal base 
type of the set may be expressed with the same 
syntax as for subrange types. 

Set variables are declared in the VAR declaration 
part, in exactly the same way as all variables in 
PASCAL, and may appear in statements literally (i.e: 
as ‘literals’) enclosed within square brackets, thus: 


VAR 
codes : Numbers; 
palette : ColourMix; 
BEGIN 
codes :=[0.. 2, 4, 8, 16, 32, 64 ]: 
palette := [Red . . Blue ]; { etc. } 


This segment would initialise the set codes to 
contain only the numbers 0 to 2 inclusive and 4, 8 
and so on, as listed. Because there is no inherent 
order in the set itself (as opposed to its base type), 
we could equally well express this set as [64, 32, 16, 
8, 4, 0..2] but notice that the subrange 2. . 0 
(illegal in an actual subrange definition) would 
merely indicate an empty range. In fact, any set 
can be initialised to an empty set of its type with the 


1114 THE HOME COMPUTER ADVANCED COURSE 


statement: AnySet :=| ], which gives rise to the only 
exception to the general rule in pascAL, namely, 
the type of any literal is known by inspection. 
Without at least one member of the set appearing 
literally, neither we nor the compiler can 
determine its type. Fortunately, the empty set can 
only occur in assignments (as in the example) or 
expressions in which the other identifiers will have 
already had their types declared. This does mean, 
however, that the empty set is a subset of every set 


- type, but that’s only natural. 


SET OPERATORS 


One of the most useful operators PASCAL provides 


for set structures is, iike DIV and MOD, a reserved 
word: IN. It enables us to test for membership of a 
set, and is a relational operator that takes two 
operands. The left-hand side must be an 
expression evaluating to one of the possible 
members of the set — in other words, a value of the 
set’s base type — and the right-hand side may be a 
set variable or set literal. ‘The whole expression will 
give a Boolean result — true if the value is a 
member of the set and false otherwise. 

So: N IN codes and Green IN palette are legal 


Boolean expressions. The usual test for a character 


being a digit could be written as: 


IF (c >= ‘0’ ) AND (c <=‘9’) THEN... 


How much less confusing to test for c’s value being 
a member of the set of characters were interested 
in, using: 


CUED 2278 2) AEN 


Or perhaps, if we are writing a program to play a 
card game: 7 


TYPE 
rank =(deuce, three, four, five, six, seven, eight, 
nine, ten, Jack, Queen, King, Ace ): 
CardSet = SET OF rank; 
VAR 
card : rank; 
pictures: CardSet; 
BEGIN 
pictures :=( Jack . . Ace ): 
IF card IN pictures THEN { etc. } 


Contrast this last example with: 


IF (card = Jack) OR (card = Queen) OR (card = King) 
UB 


_ There are also operations defined on sets as a 


whole in PASCAL. These are set intersection, union 
and difference. If B is the set of all BAsic 
programmers and P represents PASCAL people, 
then the intersection of the two sets is the set of 
programmers using both Basic and PASCAL. The 
union of P and B is the set of people who program 
in either PASCAL Or BASIC — thatis, the combination 
of the two sets. 

Set difference is, as it suggests, the result of 
removing or subtracting all members of one 
set' from the other. Thus, in pascaL notation, 





nnn annem 

















IAN McKINNELL 



















































































































































































oe 


a 



























































































































































ee 










































































































































































P — B represents all those who program in PASCAL 
but not in Basic. Similarly, the notation used for 
union is P + B, and for intersection P * B. These 
operator symbols happen to be the same as the 
well-known arithmetic operators, but the different 
class of operations should not be confused. 
Actuaily, the reason they appear so naturally in the 
context of set operations is that they represent the 
bit testing that is involved here. 

Imagine a set of eight elements. The presence of 
a particular member could be indicated by setting 
the appropriate bit in an 8-bit pattern (one byte); 
absence from the set can be set similarly by a zero. 
Membership tests, then, just require a mask or bit 
test, a set union becomes an OR operation and 
intersection will be a simple AND. These 


operations are invariably available at machine 


code level, so that the pAscaL compiler is able to 
provide set data structures and their associated 
operations very efficiently. The memory overhead 
is also minimal, and especially when the size of sets 
can be kept within a computer’s word size ( on 32- 
bit and over machines, for example), set 
Operations can be the most efficiently 
implemented ones in PASCAL. | 


ORDER OF PRECEDENCE | 


We can now conveniently summarise, all the 
operators in PASCAL. Those we haven't dealt with 
explicitly are all familiar from other languages, and 
PASCAL keeps things extremely simple by only 
having four levels of operator precedence. 
Naturally, the ‘unary’ or ‘monadic’ operators take 
precedence over all the others. These are the 
symbols + and —, which indicate the sign of a 
number and the Boolean negation operator NOT. 
The second precedence level has all the 
‘multiplication’ operators (including the division 
symbols) followed by addition/subtraction and, 
at the lowest level of precedence, all the relational 
operators including IN. 

Notice that the other two Boolean operators 
(AND and OR) are treated correctly as multiplying 


and adding operators, respectively. This faithfully 


echoes the actual Boolean algebra involved, and 
means that many relational tests are bracketed to 
override this precedence. Otherwise, for instance: 
IFN > OANDN < 10 THEN .. will give a compile 
time error, because the expression 0 AND N (which 
should be evaluated first) attempts to combine two 
integer operands with a Boolean operator. 
Perhaps this is another habit you've acquired 
from BAsic? If so, now is the time to start breaking 
it! Naturally, any operators of the same 


precedence level are evaluated from left to right, as 
usual. ‘The symbol used for assignment (:=) has a 
lower precedence than any of the above operators, 
as the expression on the right-hand side of an 
assignment must be fully evaluated before the 
assignment is made. One word of caution: you can 
never assume that any part of an expression won't 
be evaluated, so that: IF (N > 0) AND (K/N < 10 
THEN ... could crash a program if N was zero 
(creating a division by zero error !). 


THE HOME COMPUTER ADVANCED COURSE 1115 


1116 THE HOME COMPUTER ADVANCED COURSE 


Bingo!! 

A Bingo card may best be represented by a set. 
Although the base elements (integers in the range 
one to 90) are ordered, the only vital consideration Is 
whether or not a called number is on the card. In 
PASCAL parlance: ‘number IN Card’ is either true or 
false. 

The program simulates a game of Bingo by first 
reading the card numbers from the keyboard and 
then, as each number is ‘called’, testing for the set 
of called numbers being a superset of the card. The 
expression Card—Called will become the empty set 
when every member of Card is also in the set Called. 


PROGRAM Bingo ( input, output ); 
CONST 
Columns = 40; { to suit VDU } 
HalfWay = 25; { . } 
TYPE 
Bingo = SET OF 1 .. 90; 
VAR 
count : | we 10; 
Allowed, 
Called, 
Empty, 
Card : Bingo; 
number : integer; 
House : boolean; 
BEGIN 
Empty := [ ]; 
Allowed := [1 .. 90 ]; 
WriteLn ( ’*** BINGO ***’ : HalfWay ); 
WriteLn; 


WriteLn ( ‘Enter the 15 card numbers,’ ); 
WriteLn ( ‘(each followed by RETURN) :’ ); 


Card := Empty; 


FOR count := 1 TO 15 DO 


Adding a member to a set that already contains it 
leaves the set unchanged, aS does ‘removing a 
non-member. Notice that we cannot add a member 
to a set directly; but by creating a one-element set by 
enclosing the number within square brackets, we 
can obtain the union of two sets. 

As it stands, the program will allow duplicated 
card entries, and will accept an illegal number 
outside the range one to 90, causing a run-time 
error. As an exercise, can you think of a simple way 
of adding loop constructs to prevent both these 
anomalies and to reject numbers that have already 
been called? 


write ( count : 10, :7? ); 

ReadLn ( number ); 

Card := Card + [ number |] 
END; 


WriteLn; 

WriteLn ( “EYES DOWN !’ : HalfWay ); 
WriteLn; 

WriteLn ( “Now call each number : “ ); 
Called := Empty; 


REPEAT 
write ( °? ” : HalfWay ); 
ReadLn ( number ); 
Called := Called + [ number ]; 
House := Card - Called = Empty 


UNTIL House; 


WriteLn; 


WriteLn ( ‘Congratulations !’ : HalfWay ); 


WriteLn ( ‘Your numbers were :’ ); 
WriteLn; 


FOR number := 1 TO 90 DO 
IF number IN Card THEN 
write ( number : Columns DIV 8 ) 


~ 
Wa BP, 
Noh gs cai ag See 


S 

eytetes 

mai eee new Reeth 
ty Be BOON PEK Ee ee SEE 

Rik CRORE Cae tg ese 


6g BO om ge OS. ae 
By Ug Bias Oats Oe 
Bg. Nag gg eS RIB ee 
eg Tg ee 
we Seb S eee tae oe ee am 2 
Rg E Og Re eg tbs Pe Re ea 
Bp OS OR ip Bie Oks ide Bee 
ROG CR RS ee tg Oe g Ok 
Ce as ae a ON INA WR Bi 
Op Og tig Sie. Ug MR dy BS. 
PL ar ete tale aie Oh NO Ie BD 
Seg Rae og oe &. &. *: a ee Rea 
Be She tO hog tay hee i 
8. 
ee eee * 







* 
Stents 


: 
te 
ake 
: 
eee 
ss 





IAN McKINNELL 








Our extended look at the BBC Micro’s 
operating system has shown how the various 
ROM routines that make up the OS can be 
used by the programmer to augment or 
totally alter the way in which the OS 
responds to certain situations. Here, we 
round up the series with several programs 
that illustrate the uses of OS calls and point 
to some of their limitations. 


aunt 


The program we gave as an exercise in the previous 
instalment (see page 1100), demonstrates how we 

an intercept one of the OS vectors in order to 
change the way in which the OS responds to a 
certain event. The program alters the contents of 
OSWRCHV — the vector that holds the address of 
the OSWRCHV routine. This vector is held at 
addresses &20E and &20F. 

One of the functions of OSWRCH is to take BASIC 
text and print it to the screen when a program is 
listed. The main function of the machine code in 
our program is to look at the ASCII code of each 
character as it passes through the accumulator 





_ during the OSWRCH routine. If the ASCII code is 


between 64 and 91 (the character is a capital 
letter), then 32 is added to the value to give its 
lower case equivalent. In this way, the program 
actually forms a ‘wedge’ that will be executed each 
time the operating system calls OSWRCH. After our 
code has been executed, control is passed to the 
real OSWRCH routine using a JMP instruction with 
the old contents of OSWRCHV. After running th 

program, all capital letters in a program listed t 

the screen or typed in at the keyboard will b 

converted to lower case letters by our wedg 

routine. Hitting BREAK restores OSWRCHV to it 

normal value. 


MEMORY USE PROGRAM 
This listing is another utility program, which keep 


an eye on the use of memory while your 
programming. The expression: 


HIMEM—(?2+256* 73 


gives the amount of memory remaining after th 

program and variables have taken up their shar 

(locations 2 and 3 hold the address of the top of the 
BASIC variables table). The expression thus 
indicates how much memory is left for you to work 
with. However, continuously PRINTing this value 
can be a little tedious. The routine, therefore, uses 
the Character enters input buffer event (see page 
1099) to evaluate this expression each time a key is 


pressed, and sounds a ‘beep’ when the remaining 
BASIC memory falls below a certain level. The 


program is triggered by a keypress event and will 
continue to operate in the background while you 
type in your program. 

The first task of the program is for the user to 
determine the threshold at which he wants to be 
reminded of failing memory resources. This is 
done by PROCselect-memory, which sets up the 
threshold in lo-byte/hi-byte form. ‘The program is 
located at address &0A00, and — as usual for 
programs that use events — we must first save the 
contents of all the registers by pushing them onto 
the stack. After the subroutine that carries out this 
job is called, the registers are restored and an RTS is 
executed to return the control of the program to 
where it was when the event occurred. 

The main subroutine calls a further two 
subroutines to evaluate the amount of memory 
remaining. The inc routine takes the value stored in 
locations 2 and 3 and adds the lo-byte and hi-byte 
of the threshold to it, storing the result in addresses 
&70 and &71. The sub routine then carries out a 16- 


aa 
aca 


F Hea 


Ran a 

Seay ane ‘ Rane 
gic Sit a 3 Beaune f Seana Raa 
Eotnnenarnanaes 


a ary 
Pan fa i 


Baaucs 
Soa 


aegis 
Sameer 


Sa 


man OY 6 


ee 


ea G 3 
teens ie & es Pear Brennan aa ist 


A 
a 


his aa 


Baraat 
aati 
sats 





THE HOME COMPUTER ADVANCED COURSE 1117 


Renae 


Sa 
Sate 




















bit calculation, subtracting the contents of 
&70 and &71 from HIMEM. The value of HIMEM 
is stored on zero page in locations &06 and &07. 
Note here how absolute memory locations have 
been used — mainly because these locations have 
had these uses in all of the versions of BBC Basic. 

After this subtraction has been performed, line 


490 checks the sign of the result. If it is a positive . 


result, it indicates that there is still more than the 
previously set threshold of bytes of memory 
remaining. If the result is negative, there is 
insufficient memory left, and so it’s time to make a 
noise about it. The OSWRCH with A=7 call is then 
made to cause the beep. 

The two programs we have discussed so far are 
simple examples of potentially useful applications. 

ie advantage of using the operating system calls 
tly is that we can generate event-driven code 
acility unavailable 1 ic. The following 

oth use eve 






BACKGROUND MUSIC 

This program uses the Interval timer has ‘timed out 
event to play a series of musical notes while the 
computer performs other tasks. As the event 
routine runs in the background, you can save a 
program, edit it, list it or run a different program, 
while the notes are played throughout. You could 
expand this program to play a tune while a game 
program runs, for example. The tune will even be 
played during disk operations! 

The program is assembled to start at address 
&0C00. The first section is an initialisation routine 
that performs the following tasks. The event 
vector EVENTV, at addresses &220 and &221, is 
changed to point to our routine. OSBYTE 14 with X=o 
is then called to enable the Interval timer has ‘timed 
out’ event. A ‘note counter’ at location &70 is 
initialised to zero, and finally the event timer is 


1118 THE HOME COMPUTER ADVANCED COURSE 





started by a call to the clock subroutine. 

The first task of the event-handling routine is to 
save the CPU registers on the stack. A subroutine 
is then called to play a single note and the timer 
clock is reset. Finally, the registers are restored. 
One thing to note here is that the register save and 
restore parts of the program are standard to all our 
event-handling routines, and we simply change 
the code between these two blocks of instructions. 

Let’s now examine the various parts of the 
subroutine that play the notes. One note is played, 
selected from a table of notes, every time the event 
timer crosses zero. The table of notes, called 
notetable, is simply a series of bytes holding the 
pitch information for the five notes that we want tc 
play. A counter is used to determine which of the 
five notes is to be played, and the value is held in 
&70. The pitch value is retrieved and then stored at 
the appropriate place within soundtable, which is 
simply the parameter block for the OSWORD 
routine that we will later use to generate the sound. 
The counter is then incremented, thus pointing it 
to the next position within the note table for the 
next time the routine is entered. As you've only got 
five notes in the table, as soon as location &/0 
holds the value five it is reset to zero. 

The subroutine clock uses OSWORD with A=4 to 
set the event timer running. The area of memory 
called time holds the value that is to be stored in the - 
timer registers, thus specifying the time between 
the notes played. The sound subroutine performs 
the equivalent of a SOUND command, using. 
OSWORD with A=7; soundtable is the parameter 
block for this OSWORD call. The data for notetable 
and soundtable is set up by the BAsic statements in 
lines 840 and 850. 

Pressing BREAK will stop this program, by 
resetting the EVENTV contents. However, calling 
the initialise routine will set things off again. 


GRAPHICS MOVEMENT 

Our final program shows how we can use events to 
move a simple graphics shape, in this case a 
rectangle, across the screen, one position for each 


‘event. The frequency of movement therefore 


depends upon the value put into the event timer. 
This value is set up in line 1260. The definition of 
the shape to be moved, in terms of PLOT numbers, 
is stored in shapetable and is set up from a DATA 
statement — line 1220 POKEing the appropriate 
values in. Lines 1230 to 1250 set up EVENTV to 
point to our program and enable the appropriate 
event. Now let’s consider the machine code 
involved. 

This is stored in memory at the address 
specified by code%. Lines 200 to 230 do the usual 
register save operation, and lines 250 to 280 do the 
work by a series of subroutine calls. Finally, we 
restore the registers and execute an RTS. Lines 370 
to 440 save the current status of the graphics 
cursor and the current GCOL in use so that it can be 
restored after we've handled the event. 

Lines 460 to 520 deal with the movement of the 
shape. Lines 540 to 630 restore the graphics 








colours and the graphics cursor position to the 
state they were in when we entered the routine. 

Lines 650 to 720 use the OSWRCH routine to 
carry out the equivalent of a BAsic MOVE command 
to the desired x and y positions. These positions 
are stored in xpos and xpos+1 for the x co-ordinate 
and ypos and ypos+1 for the desired y co-ordinate. 
Lines 740 to 800 draw the shape, again using 
OSWRCH. The Y register is used as an index register 
in order to access the table of bytes that represents 
the shape (shapetable). The bytes are sent as a 
stream through OSWRCH. 

As the shape moves across the screen, it’s clear 
that there must be routines to update the x and y 
positions each time the event occurs. This is done 
by the routines incx and incy in lines 820 to 900. 
Once the box reaches the top of the screen, the 
routine overflow resets the x and y co-ordinates to 
zero. The routine clock uses OSWORD with A=4 to set 
the event timer off, and the routine gcol does the 
equivalent operation to a BAsic GCOL3,1 

There are several problems associated with this 
program. Run the code, and as long as the screen 
doesn’t scroll, the shape will move rather 
uncertainly across the screen. You can perform 
other operations while this is happening, and all is 





well. However, speed up the movement, by 
increasing the value in the time area of memory, 
and although the shape will move when you list 
part of the program, there could well be unusual 
characters appearing on the screen. The reason for 
this is simple — conflict between our routine, 
which is entered when an event occurs, and the 
usual OS behaviour when listing. Both require the 
use of OSWRCH and what happens is that when the 
OS listing routine is interrupted by our event, 
OSWRCH is left in a state that the listing routine is 
not expecting. 

If OSWRCH is interrupted, and is called by the 
interrupting routine, then one exit from the 
interrupting routine’s OSWRCH call is unavailable. 
OSWRCH is said to be non-reentrant. This is why 
Acorn suggest that it is unwise to use OS routines 
in event- and interrupt-handling routines. You 
can use them, but you are cautioned to proceed 
with care. These problems could be overcome by 
not using any of the OS routines while in an 
interrupt- or event-handling routine. There are 
alternatives, such as entering data directly into the 
screen RAM area to draw graphics, and this is one 
of the few times where side-stepping ROM 
routine calls is a good idea. 


THE HOME COMPUTER ADVANCED COURSE 1119 








Monitoring The 
Situation 

There are two types of 
monitor: the ‘green 
screen’ monochrome 
monitor (most 
commonly used on 
business machines 
because itis the 
easiest on the eye, and 
therefore the most 
suitable for long 
periods of accounting 
or word processing). 
and the colour monitor. 
The latter category can 
be further subdivided 
into two groups. RGB 
monitors have each of the main 
colour signals sent down separate 
cables for maximum definition, 
whereas composite video 
monitors send all the signals 
down a single line 


MONITOR 

In hardware terms, a monitor is a visual display 
unit similar to an ordinary cathode ray tube 
television except that it has no channel selecting 
facility — it is a dedicated machine to provide a 
visual display of the video signal from a computer. 
Monitors produce a much better picture than a 
standard television screen because the signals 
from the computer do not have to be ‘modulated’, 
or adapted to mimic the signal that the television 
receives from an aerial. Instead, a monitor can 
process the signal directly into the picture that 
appears on the screen. 

The two most popular types of signals used in 
monitors are ‘composite video’ and ‘RGB’. A 
composite video monitor generally has a bayonet- 
type socket fitted that is a common feature on 
many video recorders. The colour signals arrive 
from the computer together and the colours are 
decoded within the monitor itself. An RGB (red, 
green, blue) monitor signal is usually sent down a 
DIN-type socket although there are variations 
such as the use of Peri plugs. The signal is decoded 
into the separate colours before it is sent to the 
monitor, which are then transmitted along three 
individual lines. An RGB monitor generally 
provides a better picture than a composite video 
monitor. 

In software terms, a monitor is a program 


controlling several independent programs that 


may be running at the same time. The monitor will 
allocate priorities in processor and peripheral time 
and oversee the progress of each of the programs, 
passing data between them where necessary. 
Where a monitor is governing an entire system, the 
term can be referred to as an ‘operating system’ or 
‘supervisor’. 







MOTHER BOARD 


The mother boardis the main printed circuit board 
within a computer. It contains all of the major 
components and systems that are used and often 
functions without the need for any other boards. 
The components may consist of the central 
processing unit, the main memory and the input/ 
output system. Mother boards generally contain 


1120 THE HOME COMPUTER ADVANCED COURSE 


slots which allow other boards to be inserted. 
These additional boards, known as ‘daughter 
boards’, contain upgrade modules that perform 
specific additional functions, such as providing 
additional RAM, an 80-column or colour card, or 
a printer or disk interface. 

In the early days of home computing, when 
computers were the preserve of electronics 
enthusiasts, fitting additional boards to a 
computer became something of a craze as 
hobbyists competed with each other to customise 
their machines. It reached the stage where owners 
of Apple computers could no longer fit the lids on 
their computers because of all the boards that had 
been added! Although this still occurs among 
many enthusiasts, the main customers for 
daughter boards today are businesses who require 
additional boards to run specific applications on 
their personal computers. 


MOUSE 


Over the past few years the term mouse has come 
to mean two completely different things. To the 
home micro user, it refers to a device that is moved 
around a desk top, which in tum moves a 
corresponding cursor around the computer’s 
screen. When the cursor is above acommand or an 
icon, the user presses a button on the mouse. ‘This 


sends a RETURN signal to the computer, which then - 


executes the command indicated. 

Typically, this device works by having a ball 
bearing on the bottom of the mouse and a shaft 
encoder attached to a pair of encoding wheels in 
contact with the ball bearing. As the bearing rolls 
across the desk, its movements will be mirrored by 
the wheels and transmitted through the shaft 
encoder to an electrical sensor, which sends a 
digital signal to the computer. 

Until 1984, a mouse was considered something 
of a gimmick among computer users. However, 
with the launch of the Apple Macintosh, the 
industry began to realise how useful these devices 
could be and by 1985 there was a rush to produce 


Macintosh mouse-type packages for an increasing 


number of machines (see page 1050). 

A mouse can also refer to an ‘intelligent’ robotic 
device that can find its way around a previously 
unseen maze. Generally, the mouse will have 


some kind of sensor system on the front to detect. 


collisions, and will either have a system of on- 
board logic, enabling it to decide in which 
direction to move next, or else it will be attached to 
a computer that will provide the processing for it. 

The mouse moves through a maze until it 
encounters a wall, at which point it will attempt to 
move in a different direction until it finds a way 
through to the centre of the maze. On its first run, 
the mouse will ‘remember’ the directions it has 
travelled, and should be able to find the quickest 
route through the maze on the second. Robot mice 
are becoming increasingly popular with robotics 
enthusiasts and there are now world-wide 
championships, held annually, to find the world’s 
fastest mouse (see page 721). 








~. 





; : | pCR SEN ES ST FSD THAR A TS LT STE 














pra 
ae 








EEN fe 























AF oo 


UG ay Ga AW A'S DE G7 aa Nt ty 
Nits tN a 


THE HOME COMPUTER ADVANCED COURSE ARE 















































Be bh ae oe ee. ae ae =—P\ eS 
fv Ne NT ee ON TN 





























¥QeG RG GAA 





Dee Gy Ol Ee Sy a ww 
IE 
































SS OSs He ae 
eS) ee AY 





122 ATI 
EE AS a 


Ret bE eRURERL Y 
ALLE _ 

























































































Ze 





arte 
a 


‘RARER 
SELENE 


aie 


oo 





enone 


—— peice tenn 


SCR ASAE AETET 





SSR MHA ABAS 





Ph diessshshtataiatouckonnen 


HoMEROAHRS SN Va eH ataesaetbrtAtSAsctsatt on 
oti 





ee is 


EER ET 


= 


Be 


ee 


| 
| 
| 
i 


soon 


co 


GEL LER TE 


a 





see 
ents 





ENE SLAL ELCRIBE LAR ARES A LLLP AT TTB 


aA PREMISE ESET 


RAN ALR PEAR ELI IE EE TR EIGET ETT EE BRO EET 





aaa 
Ean anes 
ea 





GUARANTEE GUARANTEE GUARANTEE GUARANTEE GUARANTEE 
~~ += =—=—=—se GUARANTEE GUARANTEE GUARANTEE G __ GUARANTEE 
“Do not affix Postage Stamps f pasted in oN nes ene ea en, ea | ees... 
_ Gt. Britain, Channel Islands or N. Ireland. 


2G youare notentirely _ 


_ andit willbe either 
_exchanged,or,ifyou {f 
prefer, yourmoney will } 
- berefundedinfull. 





GUARANTEE GUARANTEE GUARANTEE GUARANTEE GUARANTEE 
GUARANTEE GUARANTEE GUARANTEE GUARANTEE GUARANTEE 
.  . GUARANTEE GUARANTEE